/**
 * Created by Bin on 2017/5/14.
 */
// 拖拽

function Drag(obj) {
    var _this = this;
    this.disX = 0;
    this.disY = 0;
    this.obj = obj;
    this.obj.on('mousedown', function (e) {
        _this.Dragdown(e);
    })
}
Drag.prototype.Dragdown = function (e) {
    var _this = this;
    this.obj.css({
        zIndex: '10'
    }).siblings().css({
        zIndex: '1'
    })
    e.preventDefault();
    this.disX = e.pageX - this.obj.offset().left;
    this.disY = e.pageY - this.obj.offset().top;
    $(document).on('mousemove', function (e) {
        _this.Dragmove(e);
    })
    $(document).on('mouseup', function () {
        _this.Dragup();
    })
}
Drag.prototype.Dragmove = function (e) {
    var offL = e.clientX - this.disX;
    var offT = e.clientY - this.disY;
    // if (offT < 0) {
    //     offT = 0;
    // }
    // if (offL < 0) {
    //     offL = 0;
    // }
    this.obj.css({
        left: offL,
        top: offT
    })
}
Drag.prototype.Dragup = function () {
    $(document).off('mousemove mouseup');
}

export default Drag;
